(function (name, factory) {
    for (var i in name) {
        if (window[name[i]] == undefined) {
            window[name[i]] = factory[i]();
        } else {
            window[name[i]] = {};
            console.log('命名重复')
        }
    }
})(["webApi", 'frDataRequest'], [
    //配置接口路径 
    function () {
        var data = {
            //          webapi:'http://114.55.235.7:9080/xwp.busbase.api/', 
            webapi: 'http://124.229.182.157:10001/xwp.busbase.api/',
            getUrl: function (url) {
                return this.webapi + url;
            },
            monitor: {
                lineInfo: 'app/monitor/getAnalogCircuitList',
                siteList: 'app/monitor/getStationList',
                vehicleList: 'app/monitor/getCircuitVehicleList',
                rotelist: 'app/monitor/rotelist',
                traffic: 'bus/statistics/traffic',
                downloads: 'bus/statistics/downloads',
                line_rank: 'bus/statistics/line_rank'
            }
        };
        return data;
    },
    function () {
        // 接口请求
        var data = {
            request: function (config) {
                $.ajax({
                    url: config.url,
                    cache: config.cache,
                    async: config.async,
                    type: config.method ? config.method : 'get',
                    contentType: config.contentType,
                    data: JSON.stringify(config.param),
                    scriptCharset: 'utf-8',
                    dataType: config.dataType,
                    timeout: config.timeout,
                    success: function (jd) {
                        if (config.success) config.success(jd);
                    },
                    error: config.error,
                    beforeSend: function (request) {
                        request.setRequestHeader("rqs-header", JSON.stringify({}));
                    },
                    complete: function (XMLHttpRequest, textStatus) {}
                });

            },
            packet: function (url, param) {
                this.url = url;
                this.param = param;
                this.method = 'post';
                this.timeout = 20000;
                this.async = true;
                this.cache = true;
                this.contentType = 'application/json;charset=UTF-8';
                this.dataType = 'json';
                this.complete = null;
                this.success = null;
                this.error = function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log(XMLHttpRequest);
                    return;
                };
            },
            ajaxRequest: function (config) {
                var json = config.param;
                var packet = new frDataRequest.packet(config.url, json);

                if (config.method) packet.method = config.method;
                if (typeof config.async != 'undefined') packet.async = config.async;
                if (typeof config.dataType != 'undefined') packet.dataType = config.dataType;

                packet.success = config.success;
                if (!config.error) {
                    packet.error = function (error) {
                        webComPhy.onCloseMask();
                        webComPhy.alertMsg({
                            msg: frDataRequest.errorMsg['0'],
                        })
                    };

                }

                if (config.error) packet.error = config.error;
                if (config.timeout != undefined) packet.timeout = config.timeout;
                frDataRequest.request(packet);
            },
        };
        return data;
    }
])